home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / bbs / callf.zip / FOSSIL.C < prev   
C/C++ Source or Header  |  1988-07-08  |  9KB  |  283 lines

  1.  
  2. #include <dos.h>
  3.  
  4. void set_baud_rate(int, int);
  5. int request_status(int);
  6. int initialize_driver(int);
  7. void deinitialize_driver(int);
  8. void raise_lower_dtr(int, int);
  9. void flush_output_buffer(int);
  10. void flow_control(int, int);
  11. int read_block(int, char *, int);
  12. int write_block(int, char *, int);
  13.  
  14. union REGS regs;
  15.  
  16. /*
  17. **    Set baud rate 
  18. **
  19. **        Input:    AH = 00H
  20. **                AL = baud rate code
  21. **                DX = port number
  22. **
  23. **  This works the same as the  equivalent IBM PC BIOS call,  except that it
  24. **  ONLY selects a baud rate.  This is passed in the high order 3 bits of AL
  25. **  as follows:
  26. **
  27. **        010 =   300 baud
  28. **        011 =   600  ''
  29. **        100 =  1200  ''
  30. **        101 =  2400  ''
  31. **        110 =  4800  ''
  32. **        111 =  9600  ''
  33. **        000 = 19200  '' (Replaces old 110 baud mask)
  34. **        001 = 38400  '' (Replaces old 150 baud mask)
  35. **
  36. **  The low order 5 bits can be implemented or not by the FOSSIL, but in all
  37. **  cases, if the low order bits of AL are 00011,  the result should be that
  38. **  the communications device should be set to eight data bits, one stop bit
  39. **  and no parity. This setting is a  MINIMUM REQUIREMENT  of Fido, Opus and
  40. **  SEAdog.  For purposes of completeness,  here are the IBM PC "compatible"
  41. **  bit settings:
  42. **
  43. **    Bits 4-3 define parity:     0 0       no parity 
  44. **                                1 0       no parity 
  45. **                                0 1      odd parity 
  46. **                                1 1     even parity 
  47. **  
  48. **    Bit 2 defines stop bits:      0        1 stop bit;  
  49. **                                  1      1.5 bits for 5-bit char;
  50. **                                           2 for others 
  51. **  
  52. **    Bits 1-0 character length:  0 0        5 bits 
  53. **                                0 1        6 bits 
  54. **                                1 0        7 bits 
  55. **                                1 1        8 bits 
  56. */ 
  57. void set_baud_rate(port, baud_rate_code)
  58.   int port, baud_rate_code;
  59. {
  60.     regs.h.ah = 0x00;
  61.     regs.h.al = baud_rate_code;
  62.     regs.x.dx = port;
  63.     int86(0x14, ®s, ®s);
  64. }
  65.  
  66. /*
  67. **    Request status
  68. **
  69. **        Input:    AH = 03H
  70. **                DX = port number
  71. **        Output:    AX = status bit mask (see below)
  72. **
  73. **  Returns with the line and modem status in AX.  Status bits returned are:
  74. **
  75. **        In AH:
  76. **            Bit 0 =    RDA  - input data is available in buffer
  77. **            Bit 5 = THRE - room is available in output buffer
  78. **            Bit 6 = TSRE - output buffer is empty
  79. **
  80. **        In AL:
  81. **            Bit 7 =    DCD  - carrier detect 
  82. **
  83. **  This can be used by the application to determine  whether carrier detect
  84. **  (CD) is set,  signifying the presence/absence of a remote connection, as
  85. **  well as monitoring both the input and output buffer status.
  86. */
  87. int request_status(port)
  88.   int port;
  89. {
  90.     regs.h.ah = 0x03;
  91.     regs.x.dx = port;
  92.     int86(0x14, ®s, ®s);
  93.     return (regs.x.ax);
  94. }
  95.  
  96. /*
  97. **    Initialize driver 
  98. **
  99. **        Input:    AH = 04H
  100. **                DX = port number
  101. **              ( BX = 4F50H
  102. **                CX = ^C flag address --- optional )
  103. **        Output:    AX = 1954H if successful
  104. **                BL = maximum function number supported
  105. **                     (not counting functions 7E and above)
  106. **                BH = rev of FOSSIL doc supported
  107. **
  108. **  This is used to tell the driver to begin  operations,  and to check that
  109. **  the driver is installed. This function should be called before any other
  110. **  communications calls are made.  At this point all interrupts involved in
  111. **  supporting the comm port (specified in DX) should be set up for handling 
  112. **  by the FOSSIL, then enabled.  If BX contains 4F50 hex,  then the address 
  113. **  specified in BX:CX is that of a ^C flag byte in the application program,
  114. **  to be incremented when  ^C is detected in the keyboard service routines.
  115. **  This is an optional service and only need be supported on machines where
  116. **  the keyboard service can't (or won't) perform an INT 1B or INT 23 when a
  117. **  Control-C is entered.  DTR is raised by this call.
  118. **
  119. **  NOTE: Should an additional call to this service occur  (2 Inits or Init,
  120. **  Read,Init, etc.) the driver should reset all buffers, flow control, etc.
  121. **  to the INIT state and return SUCCESS.
  122. */
  123. int initialize_driver(port)
  124.   int port;
  125. {
  126.     regs.h.ah = 0x04;
  127.     regs.x.dx = port;
  128.     regs.x.bx = 0;
  129.     int86(0x14, ®s, ®s);
  130.  
  131.     if (regs.x.ax == 0x1954)
  132.         return(regs.h.bl);            /* return number of fuctions */
  133.     else
  134.         return(0);
  135. }
  136.  
  137. /*
  138. **    Deinitialize driver
  139. **
  140. **        Input:    AH = 05H
  141. **                DX = port number
  142. **
  143. **  This is used to tell the driver that comm port operations are ended. The
  144. **  function should be called  when no more comm port functions will be used
  145. **  on the port specified in DX. DTR is NOT affected by this call.
  146. */
  147. void deinitialize_driver(port)
  148.   int port;
  149. {
  150.     regs.h.ah = 0x05;
  151.     regs.x.dx = port;
  152.     int86(0x14, ®s, ®s);
  153. }
  154.  
  155. /*
  156. **    Raise/lower DTR
  157. **
  158. **        Input:    AH = 06H
  159. **                DX = port number
  160. **                AL = DTR state to be set (1 = Raise, 0 = Lower)
  161. **
  162. **  This function is used to control the DTR line to the modem.    AL = 0 means 
  163. **  lower DTR (disable the modem), and AL = 1 means to raise DTR (enable the 
  164. **  modem).  No other function (except Init) should alter DTR.
  165. */
  166. void raise_lower_dtr(port, dtr)
  167.   int port, dtr;
  168. {
  169.     regs.h.ah = 0x06;
  170.     regs.h.al = dtr;
  171.     regs.x.dx = port;
  172.     int86(0x14, ®s, ®s);
  173. }
  174.  
  175. /*
  176. **    Flush output buffer
  177. **
  178. **        Input:    AH = 08H
  179. **                DX = port number
  180. **
  181. **  This is used to force any pending output.   It does not return until all 
  182. **  pending output has been sent.  You should use this call with care.  Flow
  183. **  control  (documented below)  can make your system hang on this call in a
  184. **  tight uninterruptible loop under the right circumstances.
  185. */
  186. void flush_output_buffer(port)
  187.   int port;
  188. {
  189.     regs.h.ah = 0x08;
  190.     regs.x.dx = port;
  191.     int86(0x14, ®s, ®s);
  192. }
  193.  
  194. /*
  195. **    Enable or Disable flow control on transmit
  196. **
  197. **        Input:    AH = 0FH
  198. **                AL = bit mask describing requested flow control
  199. **                DX = port number
  200. **
  201. **  This is used to stop output when the "other end" is overwhelmed, or when
  202. **  a BBS user wants to stop a screen.
  203. **
  204. **  Two kinds of flow control are supported:
  205. **
  206. **        Bit 0 = 1    Enable Receiving of XON/XOFF
  207. **        Bit 1 = 1    CTS/RTS
  208. **        Bit 2 is Reserved
  209. **        Bit 3 = 1   Enable Sending of XON/XOFF
  210. **
  211. **  Flow control is enabled, or disabled, by setting the appropriate bits in
  212. **  AL  for the types of flow control we want to ENABLE (value = 1),  and/or
  213. **  DISABLE  (value = 0),  and calling this function.  Bit 2 is reserved for
  214. **  DSR/DTR but is not currently supported in any implementation.
  215. **
  216. **  Applications  using this  function  should set all bits  ON  in the high 
  217. **  nibble of AL as well.  There is a compatible  (but not identical) FOSSIL
  218. **  driver implementation that uses the  high nibble as a control mask.   If
  219. **  your application sets the high nibble to all ones,  it will always work,
  220. **  regardless of the method used by any given driver.
  221. */
  222. void flow_control(port, bits)
  223.   int port, bits;
  224. {
  225.     regs.h.ah = 0x0f;
  226.     regs.h.al = bits;
  227.     regs.x.dx = port;
  228.     int86(0x14, ®s, ®s);
  229. }
  230.  
  231. /*
  232. **    Read block (transfer from FOSSIL to user buffer)
  233. **
  234. **        Input:    AH = 18H
  235. **                CX = maximum number of characters to transfer
  236. **                DX = port number
  237. **                 ES = segment of user buffer
  238. **                DI = offset into DS of user buffer
  239. **        Output:    AX = number of characters actually transferred
  240. ** 
  241. **  A "no-wait" block read of 0 to 0xffff characters from the FOSSIL inbound
  242. **  ring buffer to the calling routine's buffer. DS:SI are left untouched by
  243. **  the call; the count of bytes actually transferred will be in AX.
  244. */
  245. int read_block(port, ptr, len)
  246.   int port, len;
  247.   char *ptr;
  248. {
  249.     regs.h.ah = 0x18;
  250.     regs.x.dx = port;
  251.     regs.x.di = (int) ptr;
  252.     regs.x.cx = len;
  253.     int86(0x14, ®s, ®s);
  254.     return (regs.x.ax);
  255. }
  256.  
  257. /*
  258. **    Write block (transfer from user buffer to FOSSIL)
  259. **
  260. **        Input:    AH = 19H
  261. **                CX = maximum number of characters to transfer
  262. **                DX = port number
  263. **                 ES = segment of user buffer
  264. **                DI = offset into DS of user buffer
  265. **        Output:    AX = number of characters actually transferred
  266. ** 
  267. **  A  "no-wait"  block  move of 0 to 0xffff  characters  from  the  calling 
  268. **  program's buffer into the FOSSIL outbound ring buffer. The actual number
  269. **  of characters moved into the ring buffer will be returned in AX.
  270. */
  271. int write_block(port, ptr, len)
  272.   int port, len;
  273.   char *ptr;
  274. {
  275.     regs.h.ah = 0x19;
  276.     regs.x.dx = port;
  277.     regs.x.di = (int) ptr;
  278.     regs.x.cx = len;
  279.     int86(0x14, ®s, ®s);
  280.     return (regs.x.ax);
  281. }
  282.  
  283.